package com.lagou.rank;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RankReducer extends Reducer<IntWritable, NullWritable, IntWritable, IntWritable> {

    //key在shuffle阶段已经升序排好，只需把排名输出一下
    int rank = 0;
    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //数字相同时，作业没说排名相同还是递增，默认递增
        for (NullWritable value : values) {
            context.write(new IntWritable(++rank), key);
        }
    }
}
